package com.jic.order.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.order.entity.OrderInvoice;
import com.jic.order.mapper.OrderInvoiceMapper;
import com.jic.order.service.OrderInvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单发票表
 *
 * @author :
 * @version : v1.0.0
 * @email :
 * @since : 2020-03-03 11:14:45
 */
@Service
public class OrderInvoiceServiceImpl implements OrderInvoiceService {

    @Autowired
    private OrderInvoiceMapper orderInvoiceMapper;

    @Override
    public long insert(OrderInvoice orderInvoice) {
//        orderInvoice.setMemberId(BaseUserInfo.getUserId());
//        orderInvoice.setInvoiceNo(UUID.randomUUID().toString().replaceAll("-",""));
//        orderInvoiceMapper.insert(orderInvoice);
//        return orderInvoice.getId();
        return  5;
    }

    @Override
    public long delete(Long id) {
        return orderInvoiceMapper.delete(id);
    }

    @Override
    public long update(OrderInvoice orderInvoice) {
        return orderInvoiceMapper.update(orderInvoice);
    }

    @Override
    public OrderInvoice queryByPrimaryKey(Long id) {
        return orderInvoiceMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<OrderInvoice> query(OrderInvoice orderInvoice) {
        return orderInvoiceMapper.query(orderInvoice);
    }

    @Override
    public PageResult<OrderInvoice> queryPage(OrderInvoice orderInvoice, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<OrderInvoice> list = orderInvoiceMapper.queryPage(startIndex, pageQuery.getLimit(), orderInvoice);
        long count = orderInvoiceMapper.queryPageCount(orderInvoice);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}
